package com.financing.wap.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.financing.wap.common.Pager;
import com.financing.wap.common.SqlName;
import com.financing.wap.dao.IProjectCommentsDao;
import com.financing.wap.dto.ProjectCommentsDTO;
import com.financing.wap.dto.ProjectCommentsLinkDTO;

@Repository("projectCommentsDao")
public class ProjectCommentsDaoImpl extends BaseDaoImpl<ProjectCommentsDTO, Integer> implements IProjectCommentsDao{

	@SuppressWarnings({ "unchecked", "deprecation" })
	@Override
	public List<ProjectCommentsDTO> getCommentsList(ProjectCommentsDTO where,Pager pager) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("dto", where);
		param.put("pager", pager);
		List<ProjectCommentsDTO> queryForList = this.sqlMapClientTemplate.queryForList(SqlName.PRODCUT_COMMENTS_QUERY_LIST, param);
		return queryForList;
	}
	
	@SuppressWarnings({ "deprecation" })
	@Override
	public Integer countCommentsList(ProjectCommentsDTO where) {
		return  (Integer) this.sqlMapClientTemplate.queryForObject(SqlName.PRODCUT_COMMENTS_COUNT_LIST, where); 
	}

	@SuppressWarnings({ "deprecation" })
	@Override
	public ProjectCommentsDTO getComments(Integer id) {
		ProjectCommentsDTO query = (ProjectCommentsDTO) this.sqlMapClientTemplate.queryForObject(SqlName.PRODCUT_COMMENTS_QUERY, id);
		return query;
	}

	@SuppressWarnings("deprecation")
	@Override
	public int addComments(ProjectCommentsDTO comment) {
		
		return (Integer)this.sqlMapClientTemplate.insert(SqlName.PRODCUT_COMMENTS_ADD,comment);
	}
	@SuppressWarnings("deprecation")
	@Override
	public boolean addCommentsLink(ProjectCommentsLinkDTO link) {
		this.sqlMapClientTemplate.insert(SqlName.PRODCUT_COMMENTS_ADD_LINK,link);
		return true;
	}
	@SuppressWarnings("deprecation")
	@Override
	public void updateCommentsUpcount(Integer id)throws Exception {
		this.sqlMapClientTemplate.update(SqlName.PRODCUT_COMMENTS_UPDATE_UPUPCOUNT,id);
	}

	@Override
	public Class<ProjectCommentsDTO> getEntityClass() {
		return ProjectCommentsDTO.class;
	}
	@SuppressWarnings("deprecation")
	@Override
	public ProjectCommentsLinkDTO queryCommentsLink(ProjectCommentsLinkDTO projectCommentsLinkDTO) {
		return (ProjectCommentsLinkDTO) this.sqlMapClientTemplate.queryForObject(SqlName.QUERY_COMMENTS_LINK, projectCommentsLinkDTO);
	}

}
